package cn.itrip.biz.service.itripHotel;
import cn.itrip.beans.pojo.ItripAreaDic;
import cn.itrip.beans.pojo.ItripHotel;
import cn.itrip.beans.pojo.ItripLabelDic;
import cn.itrip.beans.vo.hotel.HotelVideoDescVO;
import cn.itrip.beans.vo.hotel.ItripSearchDetailsHotelVO;
import cn.itrip.beans.vo.hotel.ItripSearchFacilitiesHotelVO;
import cn.itrip.beans.vo.hotel.ItripSearchPolicyHotelVO;
import cn.itrip.dao.itripAreaDic.ItripAreaDicMapper;
import cn.itrip.dao.itripHotel.ItripHotelMapper;
import cn.itrip.common.EmptyUtils;
import cn.itrip.common.Page;
import cn.itrip.dao.itripLabelDic.ItripLabelDicMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import cn.itrip.common.Constants;
@Service
public class ItripHotelServiceImpl implements ItripHotelService {

    @Resource
    private ItripHotelMapper itripHotelMapper;
    @Resource
    private ItripAreaDicMapper itripAreaDicMapper;
    @Resource
    private ItripLabelDicMapper itripLabelDicMapper;

    public ItripHotel getItripHotelById(Long id)throws Exception{
        return itripHotelMapper.getItripHotelById(id);
    }

    public List<ItripHotel>	getItripHotelListByMap(Map<String,Object> param)throws Exception{
        return itripHotelMapper.getItripHotelListByMap(param);
    }

    public Integer getItripHotelCountByMap(Map<String,Object> param)throws Exception{
        return itripHotelMapper.getItripHotelCountByMap(param);
    }

    public Integer itriptxAddItripHotel(ItripHotel itripHotel)throws Exception{
            itripHotel.setCreationDate(new Date());
            return itripHotelMapper.insertItripHotel(itripHotel);
    }

    public Integer itriptxModifyItripHotel(ItripHotel itripHotel)throws Exception{
        itripHotel.setModifyDate(new Date());
        return itripHotelMapper.updateItripHotel(itripHotel);
    }

    public Integer itriptxDeleteItripHotelById(Long id)throws Exception{
        return itripHotelMapper.deleteItripHotelById(id);
    }

    public Page<ItripHotel> queryItripHotelPageByMap(Map<String,Object> param,Integer pageNo,Integer pageSize)throws Exception{
        Integer total = itripHotelMapper.getItripHotelCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<ItripHotel> itripHotelList = itripHotelMapper.getItripHotelListByMap(param);
        page.setRows(itripHotelList);
        return page;
    }

    @Override
    public HotelVideoDescVO getVideoDescByHotel(Long hotelId) throws Exception {
        HotelVideoDescVO hotelVideoDescVO = new HotelVideoDescVO();
        //查询酒店名
        String hotelName = itripHotelMapper.getItripHotelById(hotelId).getHotelName();
        hotelVideoDescVO.setHotelName(hotelName);
        //查询酒店商圈（多个）
        List<ItripAreaDic> result = itripAreaDicMapper.getItripAreaDicByHotelId(hotelId);
        hotelVideoDescVO.setTradingAreaNameList(new ArrayList<String>());
        if(EmptyUtils.isNotEmpty(result)){
            for(ItripAreaDic dic:result){
                hotelVideoDescVO.getTradingAreaNameList().add(dic.getName());
            }
        }
        //查询酒店功能（多个）
        List<ItripLabelDic> labels = itripLabelDicMapper.getLabelDicByHotelId(hotelId);
        hotelVideoDescVO.setHotelFeatureList(new ArrayList<String>());
        if(EmptyUtils.isNotEmpty(labels)){
            for(ItripLabelDic label:labels){
                hotelVideoDescVO.getHotelFeatureList().add(label.getName());
            }
        }
        return hotelVideoDescVO;
    }

    @Override
    public ItripSearchFacilitiesHotelVO getItripHotelFacilitiesById(Long hotelId) throws Exception {
        ItripSearchFacilitiesHotelVO itripSearchFacilitiesHotelVO = new ItripSearchFacilitiesHotelVO();
        //查询酒店设施
        itripSearchFacilitiesHotelVO.setFacilities(itripHotelMapper.getFacilitiesByHotelId(hotelId));
        return itripSearchFacilitiesHotelVO;
    }

    @Override
    public List<ItripSearchDetailsHotelVO> getSearchDetailsByHotelId(Long hotelId) throws Exception {
        //查询酒店功能（多个）
        List<ItripSearchDetailsHotelVO> desc = new ArrayList<>();
        desc = itripHotelMapper.getHotelDescById(hotelId);
        List<ItripSearchDetailsHotelVO> list = new ArrayList<ItripSearchDetailsHotelVO>();
        //查询酒店介绍
        ItripSearchDetailsHotelVO vo = new ItripSearchDetailsHotelVO();
        vo.setName("酒店介绍");
        vo.setDescription(itripHotelMapper.getItripHotelById(hotelId).getDetails());
        list.add(vo);
        for(ItripSearchDetailsHotelVO itripSearchDetailsHotelVO:desc){
            ItripSearchDetailsHotelVO vo2 = new ItripSearchDetailsHotelVO();
            vo2.setName(itripSearchDetailsHotelVO.getName());
            vo2.setDescription(itripSearchDetailsHotelVO.getDescription());
            list.add(vo2);
        }
        return list;
    }

    @Override
    public ItripSearchPolicyHotelVO getHotelPolicyById(Long hotelId) throws Exception {
        ItripSearchPolicyHotelVO itripSearchPolicyHotelVO = new ItripSearchPolicyHotelVO();
        //查询酒店政策
        itripSearchPolicyHotelVO.setHotelPolicy(itripHotelMapper.getHotelPolicyByHotelId(hotelId));
        return itripSearchPolicyHotelVO;
    }
}
